package top.linuyx.controller;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.linuyx.pojo.param.VerificationCodeSimpleMailParam;
import top.linuyx.pojo.response.ResponseData;
import top.linuyx.service.VerificationCodeService;

import javax.validation.Valid;

/**
 * @Author Linuyx
 * @Description VerificationCodeController
 * @Date Created in 2021-04-25 18:43
 */

@Controller
@RequestMapping("/verification-code")
public class VerificationCodeController {

    @Autowired
    private VerificationCodeService verificationCodeService;

    @PostMapping(value = "/bind-email", name = "发送绑定邮箱验证码")
    @RequiresRoles("user")
    @ResponseBody
    public ResponseData<String> sendBindEmailVerificationCode(@Valid @RequestBody VerificationCodeSimpleMailParam simpleMailParam){
        verificationCodeService.sendBindEmailVerificationCode(simpleMailParam);
        return ResponseData.success("验证码发送成功");
    }

    @GetMapping(value = "/update-password", name = "发送修改密码验证码")
    @RequiresRoles("user")
    @ResponseBody
    public ResponseData<String> sendUpdatePasswordVerificationCode(){
        verificationCodeService.sendUpdatePasswordVerificationCode(new VerificationCodeSimpleMailParam());
        return ResponseData.success("验证码发送成功");
    }

}
